package com.yhy.produce.callback;

import com.yhy.common.rabbitmq.callback.ConfirmCallback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Slf4j
@Component
public class MqConfirmCallback extends ConfirmCallback {

    @Override
    protected void enhance(CorrelationData correlationData) {
        String dataId = Optional.ofNullable(correlationData).orElse(new CorrelationData()).getId();
        log.debug("消息到达broker成功。自定义增强...id: {}", dataId);
    }

    @Override
    protected void compensate(CorrelationData correlationData, String cause) {
        String dataId = Optional.ofNullable(correlationData).orElse(new CorrelationData()).getId();
        log.error("消息到达broker失败。自定义补偿...id: {} cause: {}", dataId, cause);
    }

}
